package com.eastcom.providor.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.eastcom.bm.atom.Atom_PublicNe;
import com.eastcom.client.TreeNode;
import com.eastcom.providor.dao.BaseDao;
import com.eastcom.providor.dao.IPublicNeDao;

public class PublicNeDao extends BaseDao implements IPublicNeDao {

	public List<Atom_PublicNe> getAllPublicNe() throws Exception {
		try{
			return this.getObjects(Atom_PublicNe.class);	
		}
		catch(Exception e){
			throw e;
		}
	}

	public List<Atom_PublicNe> getPublicNeByDataSetId(String dataSetId) throws Exception {
		try{
			return this.getObjects("select n from Atom_DatasetNe dn ,Atom_PublicNe n where dn.neId=n.id and dn.datasetId=?",new Object[]{dataSetId});
		}
		catch (Exception e) {
			throw e;
		}
	}
	
	public List<TreeNode> getPublicNeNodeByDataSetId(String dataSetId) throws Exception {
		try{
			List<TreeNode> results=new ArrayList<TreeNode>();
			List<Atom_PublicNe> list=this.getPublicNeByDataSetId(dataSetId);
			
			for(Atom_PublicNe at:list){
				TreeNode publicNe=new TreeNode();
				publicNe.setId(at.getId());
				publicNe.setText(at.getCn_name());
				publicNe.setLeaf(true);
				results.add(publicNe);
			}
			
			return results;
		}
		catch(Exception e){
			throw e;
		}
	}

	public List<Atom_PublicNe> getAllPublicNeByDataSetId(String dataSetId) {
		return this.getObjects("from Atom_PublicNe where neType = (select dsd.neType from Atom_DatasetDefine dsd where dsd.id=?)", new String[]{dataSetId});
	}

	public List<Atom_PublicNe> getPublicNeByNeType(String neType) {
		return this.getObjects("from Atom_PublicNe where neType = ?" , new String[]{neType});
	}

	public void deletePublicNe(String pubNeID) throws Exception {
		this.deleteObject(Atom_PublicNe.class, pubNeID);
	}

	public void savePublicNe(Atom_PublicNe at) throws Exception {
		this.saveObject(at);
	}

	public void updatePublicNe(Atom_PublicNe at) throws Exception {
		this.updateObject(at);
	}

	public Atom_PublicNe getPublicNeByID(String pubNeID) throws Exception {
		return this.getObject(Atom_PublicNe.class, pubNeID);
	}

}
